package com.wangyk.rabbitmqconsole.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.FilterConfig;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Description:
 * 使用@WebFilter注解实现过滤器
 * 1、在启动类上增加@ServletComponentScan注解，自动扫描带有过滤器注解的包
 * 2、在类上使用@WebFilter和@Order组合实现
 * @Author: wangyk
 * @CreateDate: 2019/1/9$ 13:28$
 * @UpdateUser: wangyk
 * @UpdateDate: 2019/1/9$ 13:28$
 * @UpdateRemark:
 * @Version: 1.0
 */
@WebFilter(filterName="filterWebFilter",urlPatterns= {"/*"})
@Order(0)
public class FilterWebFilter implements Filter
{
    public void init(FilterConfig filterConfig)
        throws ServletException
    {
        System.out.println("FilterWebFilter初始化！！");
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException
    {
        System.out.println("执行filterWebFilter的：doFilter()方法！==>"+((HttpServletRequest)request).getRequestURL());
        //可以执行后面的过滤器
        filterChain.doFilter(request,response);
    }

    public void destroy()
    {
        System.out.println("销毁FilterWebFilter！");
    }
}
